/* expect : 100 pts */
#include "graph.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 210;
int n, type[N][N], to[N][N], dep[N][N], mp[N][N], res[N];

void build_tree(int now)
{
	int deg = NumberOfRoads(), fa_id = LastRoad();
	for(int i = 1; i <= deg; ++i)
	{
		if(!type[now][i])
		{
			Move(i, 2);
			int c = Color();
			if(c == 1)
			{
				++n;
				type[now][i] = 1;
				to[now][i] = n;
				type[n][LastRoad()] = 2;
				to[n][LastRoad()] = now;
				build_tree(n);
			}
			else if(c == 2)
			{
				type[now][i] = 4;
				Move(LastRoad(), 2);
			}
			else if(c == 3)
			{
				type[now][i] = 3;
				Move(LastRoad(), 3);
			}
		}
	}
	if(fa_id != -1) Move(fa_id, 3);
}
int sta[N], top;
inline void work(int now, int depth, int d)
{
	sta[++top] = now;
	int dep_c = depth / d % 3 + 1, deg = NumberOfRoads();
	for(int i = 1; i <= deg; ++i)
	{
		if(type[now][i] == 1)
		{
			Move(i, dep_c);
			work(to[now][i], depth + 1, d);
		}
		if(type[now][i] == 4)
		{
			Move(i, dep_c);
			int to_c = Color();
			dep[now][i] += (to_c - 1) * d;
			if(d == 81)
			{
				to[now][i] = sta[dep[now][i]];
				to[sta[dep[now][i]]][LastRoad()] = now;
			}
			Move(LastRoad(), to_c);
		}
	}
	--top;
	for(int i = 1; i <= deg; ++i)
		if(type[now][i] == 2)
			Move(i, dep_c);
}
void Inspect(int R)
{
	++n; build_tree(n);
	for(int i = 1; i <= 81; i *= 3) work(1, 1, i);
	memset(mp, 0x3f, sizeof(mp));
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			if(to[i][j])
				mp[i][to[i][j]] = 1;
	for(int k = 1; k <= n; ++k)
		for(int i = 1; i <= n; ++i)
			for(int j = 1; j <= n; ++j)
				mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j)
			++res[mp[i][j]];
	for(int i = 1; i <= R; ++i) Answer(i, res[i]);
}
/*

*/
